//
//  LZManageReviewsVideosTableViewCell.m
//  laziz_Merchant
//
//  Created by xbn_iMac on 2016/12/18.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZManageReviewsVideosTableViewCell.h"
#import "UIView+Rotation.h"
#import "UIImageView+WebCache.h"
#import "HCSStarRatingView.h"
#import "LZManageReviewsPromotionVideoListModel.h"
#import "Masonry.h"

@interface LZManageReviewsVideosTableViewCell ()

@property (weak, nonatomic) IBOutlet UIImageView *headImageView;

@property (weak, nonatomic) IBOutlet UILabel *labTitle;
@property (weak, nonatomic) IBOutlet UIView *starBgView;
@property (weak, nonatomic) IBOutlet UILabel *labNoReviewRemind;
@property (weak, nonatomic) IBOutlet UIImageView *arrowImageView;

@property (weak, nonatomic) HCSStarRatingView *starRatingView;

@end

@implementation LZManageReviewsVideosTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self.arrowImageView setLanguageRotaion];
    self.labNoReviewRemind.hidden = YES;
    self.labNoReviewRemind.text = LZLocalizedString(@"review_norating_now", nil);
    self.starBgView.backgroundColor = [UIColor clearColor];

    /*
     ==========================================Star =================================================
     */
    
    int number = 5;
    HCSStarRatingView *star = [[HCSStarRatingView alloc]initWithFrame:CGRectZero];
    star.maximumValue = number;
    star.minimumValue = 0;
    star.spacing = 2.5;
    star.allowsHalfStars = YES;
    star.accurateHalfStars = YES;
    star.tintColor = UIColorFromRGB(0xF08F4D, 1);
    star.userInteractionEnabled = NO;
    
    self.starRatingView = star;
    
    [self.starBgView addSubview:star];
    
    [star makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.starBgView);
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setModel:(LZManageReviewsPromotionVideoListModel *)model {
    _model = model;
    
    // 优惠视频图片
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",APIBaseImageUrl,model.videoPhoto]] placeholderImage:[UIImage imageNamed:@"lz_other_placehoiderImage"]];
    
    // 优惠视频名称
    self.labTitle.text = model.promotionTitle;
    
    BOOL isHaveReview = model.remarkCountPerson>0;
    // 星星指数
    self.starRatingView.hidden = !isHaveReview;
    self.labNoReviewRemind.hidden = isHaveReview;
    if (isHaveReview) {
        self.starRatingView.value = (CGFloat)model.remarkCountScore/model.remarkCountPerson;
    }
}

@end
